import request from '@/utils/request'

// 查询检查列表
export function listInspection(query) {
  return request({
    url: '/getAllInspections',
    method: 'get'
  })
}

// 查询检查详细信息
export function getInspection(id) {
  return request({
    url: '/getInspection/' + id,
    method: 'get'
  })
}

// 批量删除检查
export function batchDeleteInspection(ids) {
  const idArray = ids.split(',');
  const promises = idArray.map(id => deleteInspection(id));
  
  return Promise.all(promises).then(() => {
    return {
      code: 200,
      message: 'success',
      data: null
    }
  });
}

// 导出检查数据
export function exportInspection(query) {
  return request({
    url: '/exportInspections',
    method: 'get',
    params: query,
    responseType: 'blob'
  })
}

// 获取车辆的检查记录
export function getCarInspections(carId) {
  return request({
    url: '/getCarInspections/' + carId,
    method: 'get'
  })
}

// 上传检查报告
export function uploadInspectionReport(inspectionId, formData) {
  return request({
    url: '/uploadInspectionReport/' + inspectionId,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取所有检查记录
export function getAllInspections() {
  return request({
    url: '/api/inspections',
    method: 'get'
  })
}

// 根据ID获取检查记录
export function getInspectionById(inspectionId) {
  return request({
    url: `/api/inspections/${inspectionId}`,
    method: 'get'
  })
}

// 根据车辆ID获取检查记录
export function getInspectionsByCarId(carId) {
  return request({
    url: `/api/inspections/car/${carId}`,
    method: 'get'
  })
}

// 根据检查员获取检查记录
export function getInspectionsByInspector(inspector) {
  return request({
    url: `/api/inspections/inspector/${inspector}`,
    method: 'get'
  })
}

// 根据结果获取检查记录
export function getInspectionsByResult(result) {
  return request({
    url: `/api/inspections/result/${result}`,
    method: 'get'
  })
}

// 添加检查记录
export function addInspection(data) {
  return request({
    url: '/api/inspections',
    method: 'post',
    data
  })
}

// 更新检查记录
export function updateInspection(data) {
  return request({
    url: '/api/inspections',
    method: 'put',
    data
  })
}

// 删除检查记录
export function deleteInspection(inspectionId) {
  return request({
    url: `/api/inspections/${inspectionId}`,
    method: 'delete'
  })
}

// 根据车辆ID删除检查记录
export function deleteInspectionsByCarId(carId) {
  return request({
    url: `/api/inspections/car/${carId}`,
    method: 'delete'
  })
}

// 条件查询检查记录
export function searchInspections(data) {
  return request({
    url: '/api/inspections/search',
    method: 'post',
    data
  })
} 